<?php

class MemberController extends Zend_Controller_Action
{

	public function init()
	{
		/* Initialize action controller here */
	}

	public function indexAction()
	{
		// action body
	}

	public function loginAction()
	{
		$member_mapper = new Application_Model_MemberMapper();

		$sessLogin = new Zend_Session_Namespace('Login');

		$request 	= $this->getRequest();
		$_redirect = $request->getParam('re');

		$registry 	= Zend_Registry::getInstance();
		$auth		= Zend_Auth::getInstance();
		$url = '';

		$params = array('host'		=>'localhost',
        	'username'	=>'root',
        	'password'  =>'rootpass',
        	'dbname'	=>'thingslook'
        );
        	$DB = new Zend_Db_Adapter_Pdo_Mysql($params);

        	$authAdapter = new Zend_Auth_Adapter_DbTable($DB);
        	$authAdapter->setTableName('member')
        	->setIdentityColumn('email')
        	->setCredentialColumn('password');

        	/*** Set the input credential values ***/
        	$username = strtolower($request->getParam('username'));
        	$password = $request->getParam('password');
        	$period = $request->getParam('rdCookies');
        	$authAdapter->setIdentity($username);
        	$authAdapter->setCredential(md5($password));

        	/*** Perform the authentication query, saving the result ***/
        	$result = $auth->authenticate($authAdapter);

        	if($result->isValid()){
        		$data = $authAdapter->getResultRowObject(null,'password');
        		$auth->getStorage()->write($data);

        		//$cookie = Zend_Http_Cookie::fromString('Login=' . $username . '; ' +
        		//			'domain=localhost:8080; ');

        		$mbmEntry = $member_mapper->findByEmail($username);
        		 
        		$sessLogin->mbmId = $mbmEntry[0]->member_id;
        		if($period == 'rbForever'){
        			$sessLogin->setExpirationSeconds(3600 * 9999);
        		}
        		else{
        			$sessLogin->setExpirationSeconds(3600 * 24 * 30);
        		}
        		/*** Page redirect ***/
        		if($_redirect != null){
        			switch ($_redirect) {
        				case 'ord':
        					$this->_redirect('/order/order-confirm-form/rid/' . $_rid);
        					break;
        				case 'sell':
        					$this->_redirect('/product/findseller');
        					break;
        				default:
        					;
        					break;
        			}
        		}
        		else{
        			$this->_redirect($url);
        		}
        	}
        	else{
        		$url = '/index';
        	}
        	$this->_redirect($url);
	}

	public function registerAction()
	{
		require_once '/function/dbcconv.php';
		Zend_Date::setOptions(array('format_type' => 'php'));
		$date = new Zend_Date();

		$member_model = new Application_Model_Member();
		$member_mapper = new Application_Model_MemberMapper();
		$request = $this->getRequest();
		$code = rand(100000,999999);
			
		$_username = strtolower($this->getRequest()->getPost('username'));
		$_password = $this->getRequest()->getPost('password');
		$_confirm = $this->getRequest()->getPost('confirm');
		$_email = $this->getRequest()->getPost('email');
		$_phone = $this->getRequest()->getPost('phone');
		$_job = $this->getRequest()->getPost('job');
		$_gender = $this->getRequest()->getPost('gender');
		$_travel = $this->getRequest()->getPost('travel');
		$_description = $this->getRequest()->getPost('description');
		/*$_birth = $this->getRequest()->getPost('birth');

		if($_birth == ''){
		$_birth = '0000-00-00 00:00:00';
		}
		*/
		
		$CHALLENGE_FIELD_PARAM_NAME = "verificationCode"; 
		
		require_once('/function/DRBImageVerification/includes/challenge.php');
	
		// If there was a form post, handle it 
		if($request->getPost($CHALLENGE_FIELD_PARAM_NAME) != NULL) {
			// Check challenge string
			if(isChallengeAccepted($request->getPost($CHALLENGE_FIELD_PARAM_NAME)) === FALSE) {
			    $this->view->assign('result', '驗證碼錯誤!現在將返回出POST頁面。');
                $this->view->assign('action', $request->getBaseURL()."/product/prodform");
			}
			else{
				$member_model->setUsername($_username);
				$member_model->setPassword(md5($_password));
				$member_model->setEmail(strtolower($_email));
				$member_model->setPhone($_phone);
				$member_model->setMember_type('normal');
				$member_model->setJob($_job);
				$member_model->setGender($_gender);
				$member_model->setTravel($_travel);
				$member_model->setDescription($_description);
				$member_model->setBirth('0000-00-00 00:00:00');
				$member_model->setDeal_credit(100);
				$member_model->setRating_credit(0);
				$member_model->setTotal_deal(0);
				$member_model->setCreation_time($date->toString('Y-m-d H:i:s'));
				$member_model->setCode($code);
		
				//		$username = "whchung1987";
				//		$password = "clltilltake";
				//		$from = "66429434";
				//		$to = $_phone;
				//		$msg = "Aerospread 驗證碼: " . $code;
				//		$msg = unpack("H*hex", iconv("UTF-8", "UCS-2", $msg));
				//		$msg = "{$msg['hex']}";
				//		$url = "http://www.1328.hk/s.php?user=" . $username . "&pass=" . $password . "&to=" . $to . "&from=" . $from . "&unicode=1&mess=" . $msg . "&schtime=0";
				//
				//		$user_agent = $_SERVER['HTTP_USER_AGENT'];
				//		$c = curl_init();
				//		curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
				//		curl_setopt($c, CURLOPT_USERAGENT, $user_agent);
				//		curl_setopt($c, CURLOPT_URL, $url);
				//		$contents = curl_exec($c);
				//		curl_close($c);
		
				if(is_uploaded_file($_FILES['imgfile']['tmp_name'])) {
					// check the file is less than the maximum file size
					if($_FILES['imgfile']['size'] < 1000000){
						$member_mapper->insertAll($member_model);
							
						$entries = $member_mapper->findByUsername($_username);
						$member_id = $entries[0]->member_id;
							
						// prepare the image for insertion
						$extension= end(explode(".", $_FILES['imgfile']['name']));
						$extension = strtolower($extension);
						//move_uploaded_file($_FILES['imgfile']['tmp_name'], 'storage/userPhotos/' . $member_id . '.' . $extension);
							
						$filename = stripslashes($_FILES['imgfile']['name']);
						$uploadedfile = $_FILES['imgfile']['tmp_name'];
		
						if($extension=="jpg" || $extension=="jpeg" ){
							$src = imagecreatefromjpeg($uploadedfile);
						}
						else{
							$src = imagecreatefromgif($uploadedfile);
						}
		
						list($width,$height)=getimagesize($uploadedfile);
		
						//resize the image
						$newwidth=200;
						$newheight=($height/$width)*$newwidth;
						$tmp=imagecreatetruecolor($newwidth,$newheight);
		
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
		
						$filename = 'storage/userPhotos/' . $member_id . '.' . $extension;
		
						imagejpeg($tmp,$filename,100);
		
						imagedestroy($src);
						imagedestroy($tmp);
		
		
						$member_model->setMember_id($member_id);
						$member_model->setImage('/storage/userPhotos/' . $member_id .  '.' . $extension);
						$member_model->setWidth($text);
						$member_model->setHeight($text);
						$member_mapper->updateAll($member_model);
						$this->view->assign('result', '登記成功，驗證碼已發送到你的電郵');
						$this->view->assign('action' , $request->getBaseURL()."/" . 'user/validation-form');
					}
					else{
						// if the file is not less than the maximum allowed, print an error
						//				echo
						//                		        '<div>File exceeds the Maximum File limit</div>
						//                		        <div>Maximum File limit is '.$maxsize.'</div>
						//                		        <div>File '.$_FILES['imgfile']['name'].' is '.$_FILES['imgfile']['size'].' bytes</div>
						//                		        <hr />';
						$this->view->assign('result' , '上傳失敗，圖片超過限制的大小1MB，現在將轉到會員登記頁面。');
						$this->view->assign('action' , $request->getBaseURL()."/" . 'user/register-form');
							
					}
				}
				else{
					$this->view->assign('result', '登記成功，驗證碼已發送到你的電郵');
					$this->view->assign('action' , $request->getBaseURL()."/" . 'user/validation-form');
		
					$member_mapper->insertAll($member_model);
		
					$entries = $member_mapper->findByUsername($_username);
					$member_id = $entries[0]->member_id;
		
					$member_model->setMember_id($member_id);
					$member_model->setImage('/storage/userPhotos/default.jpg');
					$member_mapper->updateAll($member_model);
				}
		
				$sessLogin = new Zend_Session_Namespace('Login');
				$sessLogin->mbmId = $member_id;
				$this->_redirect('/index');
		
				$this->view->assign('title' , '登記成功');
				$this->view->assign('redirect' , '如果您的瀏覽器沒有自動跳轉，請點擊這裡');
			}
			$this->view->assign('title' , '訊息提示');
	        $this->view->assign('redirect' , '如果您的瀏覽器沒有自動跳轉，請點擊這裡');
		}
	}

	public function logoutAction()
	{
		$request=$this->getRequest();

		$sessLogin = new Zend_Session_Namespace('Login');
		$sessLogin->unsetAll();
		 
		require_once '/fb/facebook-php-sdk-42481fa/src/facebook.php';
		$facebook = new Facebook(array(
	      'appId'  => '354578754618136',
	      'secret' => '3eeb1509e2cd4a6faa369eb80c99ebc6',
	      'cookie' => true,
		));

		//ovewrites the cookie
		$facebook->destroySession();

		$this->_redirect('/');
	}

	public function editformAction()
	{
		$mbm_mapper = new Application_Model_MemberMapper();
		$country_mapper = new Application_Model_CountryMapper();
			
		$sessLogin = new Zend_Session_Namespace('Login');
		$_mbmId = $sessLogin->mbmId;
		$mbmEntry = $mbm_mapper->findByMemberId($sessLogin->mbmId);

		$this->view->countryEntries = $country_mapper->findAll();

		$this->view->assign('action' , '/member/edit');
		$this->view->assign('title' , '修改個人資料');
		$this->view->assign('cancel' , '取消');
		$this->view->assign('editinfo' , '修改資料');
		$this->view->assign('email' , '電子郵件');
		$this->view->assign('phone' , '電話');
		$this->view->assign('gender' , '性別');
		$this->view->assign('travel' , '常駐地區');
		$this->view->assign('birth' , '出生日期');
		$this->view->assign('image', '個人照片');
		$this->view->assign('description', '個人簡介');
		$this->view->assign('gender', '性別');
		$this->view->assign('male', '男');
		$this->view->assign('female', '女');
		$this->view->assign('change' , '更改');
		$this->view->assign('username' , '會員名稱');
		$this->view->assign('success' , '更改成功');

		$this->view->assign('usernameVal' , $mbmEntry[0]->username);
		$this->view->assign('emailVal' , $mbmEntry[0]->email);
		$this->view->assign('phoneVal' , $mbmEntry[0]->phone);
		$this->view->assign('genderVal' , $mbmEntry[0]->gender);
		$this->view->assign('birthVal' , $mbmEntry[0]->birth);
		$this->view->assign('travelVal' , $mbmEntry[0]->travel);
		$this->view->assign('imageVal' , $mbmEntry[0]->image);
		$this->view->assign('descriptionVal' , $mbmEntry[0]->description);
	}

	public function editAction()
	{
		$request = $this->getRequest();
		$mbm_mapper = new Application_Model_MemberMapper();

		$sessLogin = new Zend_Session_Namespace('Login');

		$_gender = $this->getRequest()->getPost('gender');
		$_travel = $this->getRequest()->getPost('travel');
		$_birth = $this->getRequest()->getPost('birth');
		$_description = $this->getRequest()->getPost('description');

		$_mbmId = $sessLogin->mbmId;
		$mbmEntry = $mbm_mapper->findByMemberId($sessLogin->mbmId);

		$mbmEntry[0]->setGender($_gender);
		$mbmEntry[0]->setTravel($_travel);
		$mbmEntry[0]->setBirth($_birth);
		$mbmEntry[0]->setDescription($_description);

		$mbm_mapper->updateAll($mbmEntry[0]);

		if(is_uploaded_file($_FILES['imgfile']['tmp_name'])) {
			// check the file is less than the maximum file size
			if($_FILES['imgfile']['size'] < 1000000){
				$member_id = $mbmEntry[0]->member_id;
					
				// prepare the image for insertion
				$extension= end(explode(".", $_FILES['imgfile']['name']));
				$extension = strtolower($extension);
				//move_uploaded_file($_FILES['imgfile']['tmp_name'], 'storage/userPhotos/' . $member_id . '.' . $extension);
					
				$filename = stripslashes($_FILES['imgfile']['name']);
				$uploadedfile = $_FILES['imgfile']['tmp_name'];
					
				if($extension=="jpg" || $extension=="jpeg" ){
					$src = imagecreatefromjpeg($uploadedfile);
				}
				else{
					$src = imagecreatefromgif($uploadedfile);
				}
					
				list($width,$height)=getimagesize($uploadedfile);
					
				//resize the image
				$newwidth=200;
				$newheight=($height/$width)*$newwidth;
				$tmp=imagecreatetruecolor($newwidth,$newheight);
					
				imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
					
				$filename = 'storage/userPhotos/' . $member_id . '.' . $extension;
					
				imagejpeg($tmp,$filename,100);
					
				imagedestroy($src);
				imagedestroy($tmp);
					
				$mbmEntry[0]->setImage('/storage/userPhotos/' . $member_id .  '.' . $extension);

				$mbm_mapper->updateAll($mbmEntry[0]);
					
				$this->view->assign('action' , $request->getBaseURL()."/member/index");
				$this->view->assign('result' , '更改會員資料成功 ，現在將轉到帳號管理頁面。');
			}
			else{
				// if the file is not less than the maximum allowed, print an error
				$this->view->assign('action' , $request->getBaseURL()."/member/editform");
				$this->view->assign('result' , '上傳失敗，圖片超過限制的大小1MB，現在將轉到修改個人資料頁面。');
			}
		}
		$this->view->assign('action' , $request->getBaseURL()."/member/editform");
		$this->view->assign('title' , '訊息提示');
		$this->view->assign('result' , '更改成功!現在將轉到修改帳戶資料頁面。');
		$this->view->assign('redirect' , '如果您的瀏覽器沒有自動跳轉，請點擊這裡');
	}

	public function mybidAction()
	{
		$sessLogin = new Zend_Session_Namespace('Login');
		if($sessLogin->mbmId == NULL){
			$this->_redirect('/index');
		}
			
		$pb_mapper = new Application_Model_ProductBuyMapper();
		$pb_bid_mapper = new Application_Model_ProductBuyBidMapper();

		if($sessLogin->mbmId == NULL){
			$this->view->hasLogined = 'N';
		}
		else{
			$this->view->hasLogined = 'Y';

			$this->view->pbEntries = $pb_mapper->findByPbBidMemberId($sessLogin->mbmId);
		}

		$this->view->assign('action' , '/product/sellerbid/lt/sb');
		$this->view->assign('title' , '我的投標');
		$this->view->assign('loginPlease' , '請先登入');
		$this->view->assign('subject' , '標題');
		$this->view->assign('price' , '限價');
		$this->view->assign('deadline' , '期限');
		$this->view->assign('user' , '發出人');
		$this->view->assign('status' , '狀態');
		$this->view->assign('onBid' , '進行中');
		$this->view->assign('finish' , '已結束');
		$this->view->assign('creationDate' , '開始日期');
	}

	public function myproductAction()
	{
		$sessLogin = new Zend_Session_Namespace('Login');
		if($sessLogin->mbmId == NULL){
			$this->_redirect('/index');
		}
			
		$pb_mapper = new Application_Model_ProductBuyMapper();

		if($sessLogin->mbmId == NULL){
			$this->view->hasLogined = 'N';
		}
		else{
			$this->view->hasLogined = 'Y';

			$this->view->pbEntries = $pb_mapper->findByMemberId($sessLogin->mbmId);
		}

		$this->view->assign('action' , '/product/sellerbid/lt/sb');
		$this->view->assign('title' , '我的拍賣');
		$this->view->assign('loginPlease' , '請先登入');
		$this->view->assign('subject' , '標題');
		$this->view->assign('price' , '限價');
		$this->view->assign('deadline' , '期限');
		$this->view->assign('user' , '發出人');
		$this->view->assign('status' , '狀態');
		$this->view->assign('onBid' , '進行中');
		$this->view->assign('finish' , '已結束');
		$this->view->assign('creationDate' , '開始日期');
	}

	public function scheduleAction()
	{
		$country_mapper = new Application_Model_CountryMapper();
		$this->view->countryEntries = $country_mapper->findAll();
			
		Zend_Date::setOptions(array('format_type' => 'php'));
		$date = new Zend_Date();

		$sessLogin = new Zend_Session_Namespace('Login');
		if($sessLogin->mbmId == NULL){
			$this->_redirect('/index');
		}

		$paramMonth;
		$paramYear;
			
		$events_mapper = new Application_Model_CalendarEventsMapper();
		$request = $this->getRequest();

		$this->view->month = $request->getParam('month');
		$this->view->year = $request->getParam('year');

		if($request->getParam('month') == NULL){
			$paramMonth = $date->toString('m');
		}
		else{
			$paramMonth = $request->getParam('month');
		}

		if($request->getParam('year') == NULL){
			$paramYear = $date->toString('Y');
		}
		else{
			$paramYear = $request->getParam('year');
		}
			
		$this->view->eventsEntries = $events_mapper->findByMemberId($sessLogin->mbmId, $paramMonth, $paramYear);

		$this->view->assign('addAction' , '/member/addevent');
		$this->view->assign('delAction' , '/member/delevent');
		$this->view->assign('addEvent' , '新增行程');
		$this->view->assign('delEvent' , '刪除行程');
		$this->view->assign('cfmDelEvent' , '確認刪除');
		$this->view->assign('country' , '地點');
		$this->view->assign('departure' , '出發日期');
		$this->view->assign('turnBack' , '回程日期');
		$this->view->assign('monday' , '星期一');
		$this->view->assign('tuesday' , '星期二');
		$this->view->assign('wednesday' , '星期三');
		$this->view->assign('thursday' , '星期四');
		$this->view->assign('friday' , '星期五');
		$this->view->assign('saturday' , '星期六');
		$this->view->assign('sunday' , '星期日');
		$this->view->assign('submit' , '提交');
		$this->view->assign('cancel' , '取消');
	}

	public function addeventAction()
	{
		$request=$this->getRequest();
		$counter = 0;
		$comparison = 0;
			
		$_departure = $request->getParam('departure');
		$_return = $request->getParam('return');
		$_departure_hour = $request->getParam('departure_hour');
		$_departure_minute = $request->getParam('departure_minute');
		$_return_hour = $request->getParam('return_hour');
		$_return_minute = $request->getParam('return_minute');
		$_country = $request->getParam('country');

		$country_mapper = new Application_Model_CountryMapper();
		$events_mapper = new Application_Model_CalendarEventsMapper();
		$events_model = new Application_Model_CalendarEvents();
		$sessLogin = new Zend_Session_Namespace('Login');
			
		$countryEntry = $country_mapper->findByAbbrev($_country);
			
		$depature = $_departure;
		while (strtotime($depature) <= strtotime($_return)) {
			$counter ++;
			$depature = date ("Y-m-d", strtotime("+1 day", strtotime($depature)));
		}
			
		while (strtotime($_departure) <= strtotime($_return)) {
			$comparison ++;
			if($comparison == 1){
				$events_model->setEvent_time($_departure_hour . ":" . $_departure_minute);
				$events_model->setEvent_title("出發往" . $countryEntry[0]->country_name);
			}
			else if($comparison == $counter){
				$events_model->setEvent_time($_return_hour . ":" . $_return_minute);
				$events_model->setEvent_title("由" . $countryEntry[0]->country_name . "回程");
			}
			else{
				$events_model->setEvent_time("全日");
				$events_model->setEvent_title($countryEntry[0]->country_name);
			}

			$events_model->setMember_id($sessLogin->mbmId);
			$events_model->setEvent_year(date('Y', strtotime($_departure)));
			$events_model->setEvent_month(date('m', strtotime($_departure)));
			$events_model->setEvent_day(date('d', strtotime($_departure)));
			$events_model->setEvent_desc($_country);

			$events_mapper->insertAll($events_model);

			$_departure = date ("Y-m-d", strtotime("+1 day", strtotime($_departure)));
		}
		$this->view->assign('action' , $request->getBaseURL()."/member/schedule");
		$this->view->assign('title' , '訊息提示');
		$this->view->assign('result' , '更改成功!現在將轉到行事曆頁面。');
		$this->view->assign('redirect' , '如果您的瀏覽器沒有自動跳轉，請點擊這裡');
	}

	public function profileAction()
	{
		$mbm_mapper = new Application_Model_MemberMapper();
		$relation_mapper = new Application_Model_RelationMapper();
			
		$request = $this->getRequest();
		$_mid = $request->getParam("mid");

		$sessLogin = new Zend_Session_Namespace('Login');

		if($_mid == "own"){
			$_mid = $sessLogin->mbmId;
			$this->view->mbmEntry = $mbm_mapper->findByMemberId($sessLogin->mbmId);
			$this->view->isOwn = 'T';
		}
		else{
			$this->view->mbmEntry = $mbm_mapper->findByMemberId($_mid);
			$this->view->isOwn = 'F';
		}

		$relationEntry = $relation_mapper->findByMbmIdSpecificMbmId($sessLogin->mbmId, $_mid);

		if(sizeof($relationEntry) > 0){
			$this->view->haveAdded = 'T';
		}
		else{
			$this->view->haveAdded = 'F';
		}

		$this->view->assign('addFriendAction' , $request->getBaseURL()."/" . 'member/addrelation/type/f/mid/' . $_mid);
		$this->view->assign('blockUserAction' , $request->getBaseURL()."/" . 'member/addrelation/type/b/mid/' . $_mid);
		$this->view->assign('title' , '帳戶主頁');
		$this->view->assign('username' , '用戶名稱:');
		$this->view->assign('creationDate' , '註冊日期:');
		$this->view->assign('credit' , '信用值:');
		$this->view->assign('mark' , '用戶評分:');
		$this->view->assign('description' , '個人簡介:');
		$this->view->assign('friend' , '加為朋友');
		$this->view->assign('block' , '加入黑名單');
	}

	public function eventAction()
	{
		$this->_helper->layout->disableLayout();

		$events_mapper = new Application_Model_CalendarEventsMapper();

		$request = $this->getRequest();
		$_id = $request->getParam("id");

		$this->view->eventsEntries = $events_mapper->findByEventId($_id);

		$this->view->assign('year' , '年');
		$this->view->assign('month' , '月');
		$this->view->assign('day' , '日');
	}

	public function deleventAction()
	{
		$events_mapper = new Application_Model_CalendarEventsMapper();
		$request = $this->getRequest();
			
		for ($i=0; $i<count($_POST['event_id']); $i++){
			$event_id = addslashes($_POST['event_id'][$i]);
			$events_mapper->deleteByEid($event_id);
		}

		$this->view->assign('action' , $request->getBaseURL()."/member/schedule");
		$this->view->assign('title' , '訊息提示');
		$this->view->assign('result' , '更改成功!現在將轉到行事曆頁面。');
		$this->view->assign('redirect' , '如果您的瀏覽器沒有自動跳轉，請點擊這裡');
	}

	public function addrelationAction()
	{
		$relation_model = new Application_Model_Relation();
		$relation_mapper = new Application_Model_RelationMapper();
		$mbm_mapper = new Application_Model_MemberMapper();
			
		$request = $this->getRequest();

		$_mid = $request->getParam("mid");
		$_type = $request->getParam("type");

		Zend_Date::setOptions(array('format_type' => 'php'));
		$date = new Zend_Date();

		$sessLogin = new Zend_Session_Namespace('Login');
		$mbmEntry = $mbm_mapper->findByMemberId($sessLogin->mbmId);

		$relation_model->setMember_id($sessLogin->mbmId);
		$relation_model->setSpecific_mbm_id($_mid);
		$relation_model->setCreation_time($date->toString('Y-m-d H:i:s'));

		if($_type == "f"){
			$relation_model->setRelation_type('F');
			$url = "/member/relation/type/f";
		}
		else if($_type == "b"){
			$relation_model->setRelation_type('B');
			$url = "/member/relation/type/b";
		}

		$relation_mapper->insertAll($relation_model);

		$this->_redirect($url);
	}

	public function deleterelationAction()
	{
		$relation_mapper = new Application_Model_RelationMapper();
			
		$request = $this->getRequest();
		$_rid = $request->getParam("rid");
			
		$relation_mapper->deleteByRid($_rid);
	}

	public function relationAction()
	{
		$relation_mapper = new Application_Model_RelationMapper();
			
		$request = $this->getRequest();

		$_type = $request->getParam("type");

		$sessLogin = new Zend_Session_Namespace('Login');

		if($_type == "f"){
			$this->view->relationEntries = $relation_mapper->findByMbmIdRelationType($sessLogin->mbmId, 'F');
			$this->view->assign('title' , '好友名單');
		}
		else if($_type == "b"){
			$this->view->relationEntries = $relation_mapper->findByMbmIdRelationType($sessLogin->mbmId, 'B');
			$this->view->assign('title' , '黑名單');
		}

		$this->view->assign('action', $request->getBaseURL()."/member/deleterelation/rid/");
		$this->view->assign('profileAction' , $request->getBaseURL()."/" . 'member/profile/mid/');
		$this->view->assign('username' , '用戶名稱');
		$this->view->assign('credit' , '信用值');
		$this->view->assign('mark' , '評分');
		$this->view->assign('lastTrade' , '最後交易');
		$this->view->assign('creationDate' , '日期');
		$this->view->assign('delete' , '刪除');
	}
}











